package com.yunfangdata.web.controller;

import com.yunfangdata.domain.Studentstatus;
import com.yunfangdata.query.OfficialstuQueryObject;
import com.yunfangdata.query.QueryObject;
import com.yunfangdata.query.StudentstatusObject;
import com.yunfangdata.service.IOfficialstuService;
import com.yunfangdata.service.IStudentstatusService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import com.yunfangdata.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 徐飞 on 2018/7/7.
 */
@Controller
@RequestMapping("studentstatus")
public class StudentstatusController {
    @Autowired
    private IStudentstatusService studentstatusService;
    @Autowired
    private IOfficialstuService officialstuService;

    @RequiresPermissions("studentstatus:index")
    @PermissionName("学员管理首页")
    @RequestMapping("")
    public String index(){
        return "studentstatus/list";
    }

    @RequiresPermissions("studentstatus:list")
    @PermissionName("学员管理列表")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(StudentstatusObject qo){
        return studentstatusService.query(qo);
    }


    @RequiresPermissions("studentstatus:save")
    @PermissionName("学员管理保存")
   @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Studentstatus entity) {
        JsonResult result = new JsonResult();
        try{
            studentstatusService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return  result;
    }

    @RequiresPermissions("studentstatus:update")
    @PermissionName("学员管理更新")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Studentstatus entity) {
        JsonResult result = new JsonResult();
        try{
            studentstatusService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return  result;
    }

    @RequiresPermissions("studentstatus:changeState")
    @PermissionName("学员管理状态")
    @RequestMapping("changeState")
    @ResponseBody
    public JsonResult changeState(Long id) {
        JsonResult result = new JsonResult();
        try{
            studentstatusService.changeState(id);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("审核失败");
        }
        return  result;
    }


}